// 影厅--持久层
var mongoose = require('mongoose');

const addData= async(data)=>{return await mongoose.model('theaters').create(data)};//添加影厅数据
const isHaveTheater=async(data)=>{return await mongoose.model('theaters').find(data)}//判断影厅是否已存在
const getCinemas=async()=>{return await mongoose.model("cinemas").find();};//请求影院数据
const getTheaters=async (_id)=> {//请求影厅数据
        return  await mongoose.model('theaters')
        .find()
        .populate({//把cinemasId转换为影院名字
            path:"cinemasId"
        })
        .sort({_id:-1})//排序
        .exec()
    }; 
const remove=async(data)=>{return await mongoose.model("theaters").deleteOne(data)};//删除影厅数据
const updateOne=async (_id,data)=>{ return await mongoose.model("theaters").updateOne({_id},data)};//更改影厅数据 
module.exports = {addData,getCinemas,getTheaters,remove,updateOne,isHaveTheater}